home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FIREKIT.ZIP / README.TXT < prev   
Text File  |  1996-05-27  |  10KB  |  216 lines

  1.  
  2.             FIREKIT v1.0
  3.  
  4.                  by
  5.  
  6.             John W. Ractliff
  7.              70253.3237@compuserve.com
  8.                jratclif@inlink.com
  9.  
  10.             32bit DOS4GW application.
  11.         Will run in Microsoft Windowss 32 bit mode.
  12.            Source code in ANSI C and Turbo Assembler
  13.  
  14.  
  15. The enclosed software was written by John W. Ratcliff on May 27, 1996.
  16. As of this date I am releasing this software into the public domain.
  17.  
  18. I am releasing this software into the public domain, hopefully, to make
  19. a point.  I would like to demonstrate how to write source code that is
  20. useful to other people.  I was looking at some of the various flame
  21. algorithms and source code examples and in each case they were such hard
  22. coded demos nobody could actually get them integrated into an
  23. application.
  24.  
  25. Please take a look at the source code enclosed, including the very
  26. simple and easy to understand prototypes in FLAMES.H.
  27.  
  28. The first thing you probably want to do is to just run the program.
  29. You must print out a copy of the following keyboard definitions
  30. so you will be able to operate the software.
  31.  
  32. ===== KEYBOARD CONTROLS FOR THE FLAME PROGRAM =====
  33.  
  34. 0-9   = Control the base amount of fuel being fed into the system.
  35. +     = Increase the value for the flame feeder.
  36. -     = Decrease the value for the flame feeder.
  37. ]     = Increase the quantity of fuel in the flame feeder.
  38. [     = Decrease the quantity of fuel of the flame feeder.
  39. A     = Set the flame consumption rate to zero.
  40. B     = Set the flame consumption rate to 1
  41. C     = Set the flame consumption rate to 2
  42. D     = Set the flame consumption rate to 3
  43. F     = Toggle the filter method from 4x to 8x and back.
  44.  
  45. y     = Lowercase y, increase vertical screen size.
  46. Y     = Uppercase Y, decrease vertical screen size.
  47. x     = Lowercase x, increase horizontal screen size.
  48. X     = Uppercase X, decrease horizontal screen size.
  49.  
  50. P     = Toggle the background picture mode on and off.
  51.  
  52. ESC   = Exit the program.
  53.  
  54.  
  55. ============ What are these files? =================
  56.  
  57. D.BAT            This is a batch file to invoke the Watcom debugger.
  58. FLAME.C         The C source to the FIREKIT application.
  59. FLAME.EXE        The 32 bit DOS4GW FIREKIT application.
  60. FLAME.LNK        A Microsoft make compatible link file.
  61. FLAME.MAK        A Microsoft make compatible make file.
  62. FLAME.OBJ        The Watcom 32 bit object file for FLAME.C
  63. FLAME.TXT        This documentation file.
  64. FLAMES.ASM        The assembly language source code for the flame
  65.             algorithm and support routines.  Written in
  66.             Turbo Assembler IDEAL mode.  Will run directly
  67.             under Microsoft windows 95.
  68. FLAMES.H        The C language prototype file for FLAMES.ASM
  69. FLAMES.OBJ        The assembly language object module for FLAMES.ASM
  70. IMAGE.PAK        A sample image to demonstrate merging the flame
  71.             routines into an existing application.
  72. IMAGE.PAL        The palette file that goes with IMAGE.PAK
  73.  
  74. M.BAT            A batch file which invokes the Microsoft make utility.
  75.  
  76. ==== What is FIREKIT? ===============
  77.  
  78. FIREKIT is an assembly language routine which generates a series of
  79. images which simulates fire.  Through the use of a single data structure
  80. the application programmer can effect almost every single variable in
  81. the flame routine providing a wide array of visual effects.  The FIREKIT
  82. application program, FLAME.EXE, allows you to manipulate all of these
  83. variables in real time with the keyboard.
  84.  
  85. ==== How does it work? ===============
  86.  
  87. The flame algorithm is simply a little image filter.  It will average 4
  88. or 8 pixels at a time.    The variable "fire8" in the FLAMESPEC structure
  89. controls whether to use 4 or 8 pixels in the average.  Set it to 1 if
  90. you want it to average 8 pixels, or zero if you want it to average 4.
  91. Averaging 4 pixels is faster and has a different visual look and feel
  92. than 8. When the program takes the average it will also subtract off a
  93. value from it, which causes the flame to dissapate.  You control the
  94. rate of dissapation of the flame by modifying the variable "fheight" in
  95. the FLAMESPEC structure. Typically this value is set to 1, so that it
  96. takes one less than the average at each frame.    You can set it to zero
  97. which causes an interesting looking visual effect.  When you set this
  98. value to 2, or 3, or more, the flames will not be able to get very tall
  99. before they fall out to zero.
  100.  
  101. The flame algorithm uses two frame buffers which are flip/flopped each time.
  102. At every iteration the output frame is equal to the averaged pixels of the
  103. previous frame.  These two buffers are denoted in the FLAMESPEC structure
  104. as "flame1" and "flame2".
  105.  
  106. To make the flame effect work we have to feed "fire" into the bottom of
  107. the buffers.  At each iteration randomly modulated values are placed at
  108. the bottom of the frame.  You control the strength of the fire base by
  109. setting the variable "fuelbase" in the FLAMESPEC structure.  Values between
  110. 0 and about 100 are valid.
  111.  
  112. After the fuelbase has been added the algorithm then processes the fuel
  113. feeder.  In this case a random number of fuel points are added into the
  114. stream.  The number of random fuel points is controlled by the "andmask"
  115. value in the FLAMESPEC structure.  If the and mask is, for example, set
  116. to 7, then up to 7 random fuel feeder points are placed into the
  117. stream.  Without these random fuel feeder points the flames would be
  118. very boring and static.  The strength of these fuel feeder point
  119. is controlled by the value "fuel" in the data structure.
  120.  
  121. That's all there is to it.  At each iteration the next frame is equal to
  122. an average of pixels from the previous frame, less the fuel depletion
  123. rate. Then fuel is added at the base of the image and random fuel feeder
  124. points are thrown into the mix.
  125.  
  126. ==== How to use the FLAMESPEC data structure. ==============
  127.  
  128. The flame algorith is controlled by a single data structure called FLAMESPEC.
  129. With this data structure there is nothing keeping you from creating many
  130. different active flame buffers going all at the same time.  You could allocate
  131. buffers for 5 or 6 different sized flames with different control variables
  132. and just keep calling the same routines.
  133.  
  134. Here's how the FLAMESPEC data structure is defined.
  135.  
  136.  
  137. typedef struct
  138. {
  139.   long width;    // width of flame buffer.
  140.   long height;    // height of flame buffer.
  141.   long fsize;    // number of bytes total in flame buffer (width*height)
  142.   long andmask; // andmask indicates how much extra fuel to throw in.
  143.   char *flame1; // frame 1 of flame buffer.
  144.   char *flame2; // frame 2 of flame buffer.
  145.   long *jitter; // 512 dword jitter table, used to throw random fuel in.
  146.   long seed;    // current random number seed.
  147.   long fheight; // controls rate of flame consumption, from 0 to about 4
  148.   long fuel;    // the controls the strength of the fuel feeder.
  149.   long fuelbase; // this is the base fuel strength.
  150.   long fire8;    // true if doing 8 pixel average for flames.
  151.   long ScreenX; // destination Screen X for flamecopy.
  152.   long ScreenY; // destination Screen Y for flamecopy
  153.   char ctrans[256];    //the color palette translation table if used.
  154. } FLAMESPEC;
  155.  
  156. In the main application program FLAME.C contains a routine which will
  157. allocate and initialize a FLAMESPEC data structure.
  158.  
  159. The routines provided to setup and manage FLAMESPEC data structures
  160. are written in C, and are as follows:
  161.  
  162. // This routine will initialize a framspec structure of the width and
  163. // height specified.  It will allocate the memory for the frame buffers
  164. // and the jitter table (precomputed randomized offset values for the
  165. // fuel dump stage).  If this routine returns a zero then it was unable
  166. // to allocate enough memory for the buffers.  If it returns one then
  167. // the flamespec buffer is ready to go.
  168. int  CreateFlame(FLAMESPEC *f,long wid,long hit);
  169.  
  170. // This routine frees up the memory allocated by a CreateFlame call.
  171. void DestroyFlame(FLAMESPEC *f);
  172.  
  173. // This is a routine which loads a background image and color palette
  174. // which is used to demonstrate merging the flame output into an existing
  175. // application.
  176. char * LoadPicture(char *fname,char *imagepal);
  177.  
  178. // This routine will build a color translate table which translates colors
  179. // from the flame palette into the application's own color palette.  The
  180. // translation table is "ctrans" inside the FLAMESPEC structure.
  181. void FlameColorMatch(FLAMESPEC *f,unsigned char *imagepal,unsigned char *fpal);
  182.  
  183. ===== What do the assembly language routines do? ==================
  184.  
  185. // These are DOS only functions! They handle support for going directly
  186. // to the Mode 13 320x200 VGA screen.  Under Windows you should use directdraw
  187. // WinG or something else to update your blits.
  188. void cdecl FlameStart(void); // turn 320x200 graphics mode on and set palette (DOS only)
  189. // For the moment this routine is set to NOT copy the *LAST 3 SCANLINES* of
  190. // the flame buffer.  That's because the last 3 scanlines contain the fuel
  191. // feeder area, which can often just look like random noise until it filters
  192. // up into the flame region.
  193. void cdecl FlameCopy(FLAMESPEC *f); // copy the flame to the Mode13 VGA screen.
  194. void cdecl FlameStop(void); // turn 320x200 graphics mode off (DOS only)
  195. void cdecl FlameZeroScreen(void); //erase screen.
  196. void cdecl FlameImage(char *image); // copy vga screen image.
  197. void cdecl FlameDAC(char *pal); // set vga color palette.
  198. void cdecl FlamePal(char *fpal); // set flame palette, and retrieve settings.
  199.  
  200.  
  201. // This routine has self-modified code in it!  Under Windows this will
  202. // cause a protection fault unless you change the read/write access to
  203. // this section of memory!  There is no way *not* to use self-modified
  204. // code for this routine if the program is to support variable width
  205. // flame buffers, which it does.
  206. void cdecl FlameFrame(FLAMESPEC *f);
  207.  
  208. // Copies the flame from FLAMESPEC into the destination "image", but
  209. // translates the flame colors into the application color palette and
  210. // handles a translucency for flames that are near zero.
  211. void cdecl FlameCopyTranslate(FLAMESPEC *f,char *image);
  212.  
  213. // Returns which entry in the 8 bit RGB color palette "pal" is closest
  214. // to the 8 bit red/green/blue value passed.
  215. long cdecl FlameClosestColor(char *pal,long red,long green,long blue);
  216.